package com.health.fragment.jtys;

import com.blankj.utilcode.util.ToastUtils;
import com.health.tools.NovaAppUtils;
import com.health.tools.SPUtil;
import com.health.viewscontrols.NovaApplication;
import com.health.R;
import com.health.adapter.MainMenuGridAdapter_AdminJTYS;
import com.health.fragment.NovaFragment;
import com.health.viewscontrols.medical.BleConfigActivity;
import com.health.viewscontrols.settings.DataDownLoadMainActivity;
import com.health.viewscontrols.settings.DataSynchronizationMainActivity;
import com.health.viewscontrols.settings.DrugManagerActivity;
import com.health.viewscontrols.settings.SystemSettingActivity;
import com.health.tools.GlobalConts;
import com.health.viewscontrols.settings.WebViewActivity;
import com.novabluetooth.views.BluetoothDeviceBindActivity2;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 医生设置页面
 * 
 * @author nova
 *
 */
public class JTYSSettings extends NovaFragment {

	private GridView gd_menu;
	private MainMenuGridAdapter_AdminJTYS menuAdapter;
	protected ProgressDialog progressDialog;
	private View jtysSettingView = null;

	@Override
	public View findViews(LayoutInflater inflater) {
		jtysSettingView = inflater.inflate(R.layout.jtys_settings, null);
		initViews(jtysSettingView);
		System.out.println("机构编号："+NovaApplication.getJgbh());
		return jtysSettingView;
	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		// 菜单选项
		gd_menu.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// 0"系统设置", 1"蓝牙设备绑定",2"数据上传", 3"综合统计"
				Intent intent = null;
				if (position == 0) {
					// 0 "系统设置",
					intent = new Intent(getActivity(), SystemSettingActivity.class);
				} else if (position == 1) {
					// 1 "蓝牙设备绑定",
					if (NovaApplication.idCardTool != null) {
						NovaApplication.idCardTool.removeListener();
						NovaApplication.idCardTool.setiNeedReadCount(1);
					}
					intent = new Intent(getActivity(), BluetoothDeviceBindActivity2.class);
				}else if (position == 2) {
					//同步数据
					intent = new Intent(getActivity(), DataDownLoadMainActivity.class);
				} else if (position == 3) {
					// 同步机构人员
					intent = new Intent(getActivity(), DataSynchronizationMainActivity.class);
				} else if (position == 4) {
					// 药品维护
					intent = new Intent(getActivity(), DrugManagerActivity.class);
				} else if (position == 5) {
					// 软件更新
//					String url = "http://txmp.guantangyiliao.com/app/gxmb.html";
//					String url = "http://txmp.guantangyiliao.com/liti/index.html";
//					intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

					NovaAppUtils.downLoadApk(getActivity(),
							"讯飞输入法",
							"https://srf.xunfei.cn/a",
							Environment.getExternalStorageDirectory() + "/Download/health/xunfei.apk");
				} else if (position == 6) {
					NovaAppUtils.downLoadApk(getActivity(),
							"360相机",
							"https://cloudcdn.c360dn.com/camera360-android-release.apk",
							Environment.getExternalStorageDirectory() + "/Download/health/camera360.apk");
				} else if (position == 7) {
					intent = new Intent(getActivity(), BleConfigActivity.class);
				}

				if (intent != null ){
					startActivity(intent);
				}
			}
		});
	}

	@Override
	public void setData() {

	}

	/**
	 * 初始化布局
	 * 
	 * @author 王婷婷
	 * @date 2017年2月10日 下午3:17:44
	 */
	private void initViews(View v) {

		LinearLayout ll_back = (LinearLayout)v.findViewById(R.id.ll_back);
		ll_back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				getActivity().finish();
			}
		});
		gd_menu = (GridView) v.findViewById(R.id.gd_menu);
		TextView tvJg = (TextView)v.findViewById(R.id.tv_jg);
		SharedPreferences shareDatas = getActivity().getSharedPreferences(SPUtil.SP_NAME, Context.MODE_PRIVATE);
		String jg = shareDatas.getString(SPUtil.STR_JDDW,"");
		tvJg.setText(jg);
		menuAdapter = new MainMenuGridAdapter_AdminJTYS(getActivity(), GlobalConts.MENU_SETTINGS);
		gd_menu.setAdapter(menuAdapter);

	}

}
